package com.kiragame.couplescreen.service;

import com.kiragame.couplescreen.MainActivity;
import com.kiragame.couplescreen.quickblox.QuickBloxManager;
import com.kiragame.couplescreen.service.NetworkReceiver.OnNetworkListener;
import com.kiragame.couplescreen.utils.KiraGameLog;

import android.app.Service;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.os.IBinder;

public class AppService extends Service {
	NetworkReceiver networkReceiver;
	@Override
	public void onCreate() {
		super.onCreate();
		//QuickBloxManager.getInstance(this);
		networkReceiver = new NetworkReceiver();
		networkReceiver.setOnNetworkListener(new OnNetworkListener() {

			@Override
			public void onOnline() {
				KiraGameLog
				.d("connect internet success!");
			}

			@Override
			public void onOffine() {
				KiraGameLog
						.d("Can't connect to server. Please check your network!");
			}
		});
		this.registerReceiver(networkReceiver, new IntentFilter(
				ConnectivityManager.CONNECTIVITY_ACTION));
		KiraGameLog.d("start service app success!");
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		return START_STICKY;
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}
	
	@Override
	public void onDestroy() {
		//startAppService();
		unregisterReceiver(networkReceiver);
		QuickBloxManager.getInstance(this).onDestroy();
		super.onDestroy();
	}
	private void startAppService() {
		Intent intent = new Intent(this, ServiceAppBroadcastReceiver.class);
		sendBroadcast(intent);
	}
	
	
}
